package cn.magicduck.demo;

import cn.magicduck.demo.store.ICommodity;
import cn.magicduck.demo.store.impl.CardCommodityService;
import cn.magicduck.demo.store.impl.CouponCommodityService;
import cn.magicduck.demo.store.impl.GoodsCommodityService;

/**
 * @projectName: design-pattern-demo
 * @className: StoreFactory
 * @description: 商店工厂
 * @author: MagicDuck
 * @create: 2020-07-16 16:31
 **/
public class StoreFactory {

    /**
     * 获得商品服务
     * @param commodityType 商品类型
     * @return              商品服务
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (null == commodityType) {
            return null;
        }
        if (1 == commodityType) {
            return new CouponCommodityService();
        }
        if (2 == commodityType) {
            return new GoodsCommodityService();
        }
        if (3 == commodityType) {
            return new CardCommodityService();
        }
        throw new RuntimeException("不存在的商品服务类型");
    }
}
